set scheme s1mono

********************************************************************************
** look at interest rates and LTVs by origination_year in McDash
********************************************************************************


use "$DATA_MCDASH/McDash_Loans", clear
replace original_interest_rate = 100 * original_interest_rate
gen origination_year = 1979 + ceil(origination_month / 12)

gen subprime = original_credit_score<=660
gen subprime_rate = original_interest_rate if subprime==1
gen subprime_LTV = original_ltv  if subprime==1

gen imputed_LTV = 100*(original_loan_amount / original_property_value)
gen subprime_LTV_imputed = imputed_LTV  if subprime==1

collapse  (mean) rate = original_interest LTV = original_ltv  subprime_rate subprime subprime_LTV subprime_LTV_imputed, by(origination_year)
save "$DATA_OUT/processing/interest_rates_by_year_McDash", replace



********************************************************************************
** look at interest rates and LTVs by origination_year in NMDB
********************************************************************************

use "$NMDB/nmdb_20210113_v130_loans.dta", clear

gen subprime = score_orig_1<=660
gen subprime_rate = interest if subprime==1
gen subprime_LTV = ltv if subprime==1

collapse  (mean) rate_NMDB = interest LTV = ltv subprime_rate_NMDB = subprime_rate subprime_NMDB = subprime subprime_LTV_NMDB = subprime_LTV, by(open_year)

rename open_year origination_year
merge 1:1 origination_year using "$DATA_OUT/processing/interest_rates_by_year_McDash", keep(match)
keep if origination_year>=2000

replace subprime_LTV = 100 * subprime_LTV 

line subprime_LTV_imputed origination_year || line subprime_LTV_NMDB origination_year, lpattern("-") legend(label(1 "McDash") label(2 "NMDB")) ytitle("LTV") xtitle("Year") 
graph export "$OUTPUT/subprime_LTVs_McDash_vs_NMDB.pdf", replace


line rate origination_year || line rate_NMDB origination_year, lpattern("-") legend(label(1 "McDash") label(2 "NMDB")) ytitle("Interest Rate") xtitle("Year")
graph export "$OUTPUT/interest_rates_McDash_vs_NMDB.pdf", replace

line subprime_rate origination_year || line subprime_rate_NMDB origination_year, lpattern("-") legend(label(1 "McDash") label(2 "NMDB")) ytitle("Interest Rate") xtitle("Year")
graph export "$OUTPUT/subprime_interest_rates_McDash_vs_NMDB.pdf", replace

